package com.hope.bubble;

import com.hope.bubble.jwt.JwtAuthenticationFilter;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@MapperScan(basePackages = "com.hope.bubble.mapper")
@SpringBootApplication
@RestController
public class BubbleCommunityApplication extends SpringBootServletInitializer {


    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(BubbleCommunityApplication.class);
    }

    //jwt 过滤器
    @Bean
    public FilterRegistrationBean jwtFilter() {
        //注册Filter
        final FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        //初始化 JwtAuthenticationFilter  过滤器对象
        JwtAuthenticationFilter filter = new JwtAuthenticationFilter();
        //调用 registrationBean 把过滤注册到全局
        registrationBean.setFilter(filter);
        return registrationBean;
    }
    public static void main(String[] args) {
        SpringApplication.run(BubbleCommunityApplication.class, args);
    }

    //健康检查
    @GetMapping
    public String hello(){
        return "success";
    }
}
